import matplotlib.pyplot as plt
from matplotlib import animation
import numpy as np
p = 2
fig = plt.figure(figsize=(12,9))
ax = fig.add_subplot(autoscale_on=False, projection='polar')
ax.set_rlim(0,8)

trace, = ax.plot([],[],'-', lw=1)
theta_text = ax.text(0.05,0.95,'',transform=ax.transAxes)
textTemplate = 'e = %.1f\n'

theta = np.arange(-3.1,3.2,0.1)
def animate(e):
    rho = p/(1-e*np.cos(theta))
    trace.set_data(theta,rho)
    theta_text.set_text(textTemplate % e)
    return trace, theta_text

frames = np.arange(-2,2,0.1)
ani = animation.FuncAnimation(fig, animate, 
    frames, interval=100, blit=True)
ani.save("polar.gif",dpi=500)

plt.show()
